<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class checkNetDevTask extends baseWemTask
{
    private $fileLogger;

      
    public function configure()
    {
        parent::configure();
        
        $this->name      = 'checkNetDev';
        $this->briefDescription = 'Tutorial';
        
        //OPTIONS
        $this->addOptions(array(
            new sfCommandOption('type', null,sfCommandOption::PARAMETER_REQUIRED, 'Network Device Type', 'Osiride')));
        
        //ARGUMENTS
    }
    
    
    public function execute($arguments = array(), $options = array())
    {
        
        $this->addFileLogger();
        
        $this->ConnectDB();
        
        //registra l'esecuzione del task
        $tasklog=seth::regTaskStart($this->name, "", $options );
        
        $range=sfConfig::get('app_checknetdev_range',7);
        
            
        $devices=Doctrine_Core::getTable('NetDev')->findByType($options['type']);  
        try{   
            foreach ($devices as $dev) {
                if ($dev->getPingable()){
                    
                $this->logBlock('Checking '.$dev->getName(), 'INFO');
                
                $opt=array("verbose");
                if ($options['debug'])
                    array_push ($opt, "debug");
                $args=array('host'=>  $dev->getIp1(), "prot" => "ICMP", "iter" => 3); 
                $result=$this->runTask("wem:isUp", $args ,$opt);
                
                Doctrine_Core::getTable("CheckNetDev")->appendNewCheck($dev,$result);
                
                }
         }

         }catch(Exception $e)  
         {

             seth::regTaskEnd($tasklog, FALSE);
             die($e->getMessage().". ".$e->getTraceAsString());
         }
        //registra la fine dell'esecuzione del task
         seth::regTaskEnd($tasklog, true);
                  
    }
}

?>
